import { aboutUser } from "../../store";
import { getListApi } from "../../api/common";

Page({
  data: {
    videoList: [],
    userInfo: aboutUser.getUserInfo(),
  },

  onLoad(options) {
    tt.setNavigationBarTitle({ title: "历史观看" });
  },

  onShow() {
    aboutUser.getUserInfo().userId && this.getList();
  },

  async getList() {
    let { userInfo } = this.data;
    const res = await getListApi({ pageNum: 1, pageSize: 1000, uid: userInfo.userId, tableType: 1 });
    if (res.code == 200) {
      this.setData({ videoList: res.data });
    }
  },

  //跳转新范式编写的播控组件
  goPlayletExtension(e) {
    if (tt.canIUse("getPlayletManager")) {
      const vid = e.currentTarget.dataset?.vid;
      const ablumId = e.currentTarget.dataset?.id;
      const episodesId = e.currentTarget.dataset?.episodesid;
      tt.navigateTo({ url: `/page/playlet-extension/index?seq=1&tt_album_id=${ablumId}&tt_episode_id=${episodesId}&vid=${vid}` });
    } else {
      // ... 跳转至开发者自有播放页
      tt.showModal({ title: "提示", content: "请升级宿主版本", showCancel: false });
    }
  },
});
